cc.Class({
    extends: cc.Component,

    properties: {
        scrollView: {
            default: null,
            type: cc.ScrollView,
            tiptool: "scrollView"
        },
    },



    // onLoad () {},

    start() {
        this._scrollViewContent = this.scrollView.content;
        // for (let index = 0; index < 6; index++) {
        //     this.newItem("item" + index, function (newNode) {
        //         if (newNode) {
        //             this._scrollViewContent.addChild(newNode);
        //         }
        //     }.bind(this));
        // }
        cc.loader.loadRes("prefab/item", cc.Prefab, function (err, prefab) {
            for (var i = 0; i < 6; i++) {
                var a = cc.instantiate(prefab);
                a.children[0].getComponent(cc.Label).string = 'index' + i;
                this._scrollViewContent.addChild(a);
            }
        }.bind(this));
    },

    newItem(item, callBack) {
        let newNode = null;
        if (!this._itemPool) {
            this._itemPool = new cc.NodePool();
        }
        if (this._itemPool.size() > 0) {
            newNode = this._itemPool.get();
            this._setItem(newNode, item, callBack);

        } else {
            cc.loader.loadRes("prefab/item", cc.Prefab, function (err, prefab) {
                if (err) {
                    return;
                }
                newNode = cc.instantiate(prefab);
                this._setItem(newNode, item, callBack);
            }.bind(this));
        }
    },

    _setItem(newNode, item, callBack) {
        newNode.getChildByName("Label").getComponent(cc.Label).string = item;
        if (callBack) {
            callBack(newNode);
        }
    }


    // update (dt) {},
});